package org.ithang.application.operationLog;

import org.ithang.tools.model.Action;
import org.ithang.tools.model.ActionResult;
import org.ithang.tools.model.ActionValues;
import org.ithang.tools.model.Pager;
import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ithang.application.operationLog.bean.OperationLog;
import org.ithang.application.operationLog.service.OperationLogService;

/**
 * 操作日志
 * @author zyt 控制器
 *
 */
@Controller
@RequestMapping("/app/operationLog")
public class OperationLogAction extends Action<OperationLog>{

    @Autowired
    private OperationLogService operationLogService; 


    @ResponseBody
	@RequestMapping(value="add",method=RequestMethod.POST)
	public ActionResult add(OperationLog operationLog){
		operationLogService.add(operationLog);
		return success();
	}
	
	 @RequestMapping("form")
    public String form(@RequestParam(value="id",required=false)Long id,Model m){
    	if(null!=id){
    		OperationLog bean=operationLogService.get(id);
    		m.addAttribute(bean);
    	}else{
    		m.addAttribute(new OperationLog());
    	}
    	return "app/operationLog/form";
    }
	
	
	@ResponseBody
	@RequestMapping(value="update",method=RequestMethod.POST)
	public ActionResult update(OperationLog operationLog){
		operationLogService.update(operationLog);
		return success();
	}


    @ResponseBody
	@RequestMapping(value="get",method=RequestMethod.GET)
	public ActionResult get(Long id){
		OperationLog r=operationLogService.get(id);
		return success(r);
	}
	
	@ResponseBody
	@RequestMapping(value="delete",method=RequestMethod.POST)
	public ActionResult delete(@RequestParam(value="id",required=false)Long id,@RequestParam(value="ids",required=false)String ids){
		
		if(null!=id&&id>0){
			operationLogService.delete(id);	
		}
		
		if(null!=ids&&ids.length()>0){
			operationLogService.batchDelete(ids.split(","));
		}
		
		return success();
	}
	
	@ResponseBody
	@RequestMapping(value="list",method={RequestMethod.GET,RequestMethod.POST})
	public ActionResult list(Long... ids){
		return success(operationLogService.list(ids));
	}
	
	@ResponseBody
	@RequestMapping(value="page",method=RequestMethod.POST)
	public ActionResult page(OperationLog operationLog,Pager<OperationLog> page){
	    page.setBean(operationLog);
	    List<OperationLog> data=operationLogService.page(page);
	    page.setData(data);
		return success(page);
	}
	
	@ResponseBody
	@RequestMapping(value="query",method=RequestMethod.POST)
	public ActionResult query(HttpServletRequest request){
		ActionValues values=new ActionValues(request);
		return success(operationLogService.query(values));
	}
     

}